package org.seedltd.upms.controller.detection;

import org.seedltd.core.base.BaseController;
import org.seedltd.core.validation.Save;
import org.seedltd.core.validation.Update;
import org.seedltd.springsecurity.utils.UserUtils;
import org.seedltd.upms.model.detection.form.DetectionMpConfigForm;
import org.seedltd.upms.model.detection.vo.DetectionMpConfigVO;
import org.seedltd.upms.service.detection.DetectionMpConfigService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;

/**
 *
 * 小程序配置控制器
 * 
 * @author laizuan
 * @version 1.0
 * @since 2021/08/12
 */
@RestController
@AllArgsConstructor
@RequestMapping("/detectionMpConfig")
public class DetectionMpConfigController extends BaseController<DetectionMpConfigService> {

    /**
     * 获取详情
     * 
     * @return 小程序配置
     */
    @GetMapping(value = "/get")
    public DetectionMpConfigVO get() {
        Long companyId = UserUtils.getCompanyId();
        return baseService.findById(companyId);
    }

    /**
     * 修改
     * 
     * @param form
     *            小程序配置表单数据
     * @return 修改状态。true标识修改成功，false标识修改失败
     */
    @PostMapping(value = "/update")
    @PreAuthorize("hasAuthority('detection:mpConfig:update')")
    public boolean update(@RequestBody @Validated({Update.class, Save.class}) DetectionMpConfigForm form) {
        Long companyId = UserUtils.getCompanyId();
        form.setId(companyId);
        return baseService.update(form);
    }
}